@@ -0,0 +1,3 @@ |
||
| 1 |
+# Place all the behaviors and hooks related to the matching controller here. |
|
| 2 |
+# All this logic will automatically be available in application.js. |
|
| 3 |
+# You can use CoffeeScript in this file: http://coffeescript.org/ |
@@ -0,0 +1,3 @@ |
||
| 1 |
+// Place all the styles related to the admin_panel controller here. |
|
| 2 |
+// They will automatically be included in application.css. |
|
| 3 |
+// You can use Less here: http://lesscss.org/ |
@@ -31,4 +31,52 @@ |
||
| 31 | 31 |
|
| 32 | 32 |
.top-container {
|
| 33 | 33 |
margin-top: 60px; |
| 34 |
+} |
|
| 35 |
+ |
|
| 36 |
+// Admin Dashboard Stats layout |
|
| 37 |
+ |
|
| 38 |
+.summary {
|
|
| 39 |
+ display: table; |
|
| 40 |
+ width: 100%; |
|
| 41 |
+ padding: 0; |
|
| 42 |
+ margin: 0 0 20px 0; |
|
| 43 |
+} |
|
| 44 |
+ |
|
| 45 |
+.summary .count {
|
|
| 46 |
+ display: block; |
|
| 47 |
+ font-size: 1.75em; |
|
| 48 |
+ font-weight: bold; |
|
| 49 |
+} |
|
| 50 |
+ |
|
| 51 |
+.summary ul {
|
|
| 52 |
+ margin: 0; |
|
| 53 |
+ padding: 0; |
|
| 54 |
+ overflow: hidden; |
|
| 55 |
+ display: table-row; |
|
| 56 |
+} |
|
| 57 |
+ |
|
| 58 |
+.summary li {
|
|
| 59 |
+ margin: 0; |
|
| 60 |
+ padding: 19px; |
|
| 61 |
+ display: table-cell; |
|
| 62 |
+ border-right: 1px solid #eee; |
|
| 63 |
+} |
|
| 64 |
+ |
|
| 65 |
+.summary a {
|
|
| 66 |
+ font-size: 1.2em; |
|
| 67 |
+ line-height: 1.4em; |
|
| 68 |
+ text-transform: uppercase; |
|
| 69 |
+ color: #000; |
|
| 70 |
+} |
|
| 71 |
+ |
|
| 72 |
+.summary a:hover .count {
|
|
| 73 |
+ text-decoration: none; |
|
| 74 |
+} |
|
| 75 |
+ |
|
| 76 |
+// admin sidebar |
|
| 77 |
+ |
|
| 78 |
+.well-micro {
|
|
| 79 |
+ background-color: #f5f5f5; |
|
| 80 |
+ border: 1px solid #e3e3e3; |
|
| 81 |
+ margin-left: 28px; |
|
| 34 | 82 |
} |
@@ -0,0 +1,19 @@ |
||
| 1 |
+class AdminPanelController < ApplicationController |
|
| 2 |
+ |
|
| 3 |
+ def index |
|
| 4 |
+ redirect_to admin_dashboard_path |
|
| 5 |
+ end |
|
| 6 |
+ |
|
| 7 |
+ def dashboard |
|
| 8 |
+ @users = User.all |
|
| 9 |
+ @posts = BlogPost.all |
|
| 10 |
+ end |
|
| 11 |
+ |
|
| 12 |
+ def posts |
|
| 13 |
+ @posts = BlogPost.all |
|
| 14 |
+ end |
|
| 15 |
+ |
|
| 16 |
+ def users |
|
| 17 |
+ @users = User.all |
|
| 18 |
+ end |
|
| 19 |
+end |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 |
class BlogPostsController < ApplicationController |
| 2 | 2 |
|
| 3 |
- before_filter :authenticate_user, only: [:edit, :update, :destroy, :list] |
|
| 3 |
+ before_filter :authenticate_user, only: [:edit, :update, :destroy] |
|
| 4 | 4 |
|
| 5 | 5 |
before_action :set_blog_post, only: [:show, :edit, :update, :destroy] |
| 6 | 6 |
|
@@ -9,10 +9,6 @@ class BlogPostsController < ApplicationController |
||
| 9 | 9 |
def index |
| 10 | 10 |
@blog_posts = BlogPost.all |
| 11 | 11 |
end |
| 12 |
- |
|
| 13 |
- def list |
|
| 14 |
- @blog_posts = BlogPost.all |
|
| 15 |
- end |
|
| 16 | 12 |
|
| 17 | 13 |
# GET /blog_posts/1 |
| 18 | 14 |
# GET /blog_posts/1.json |
@@ -80,6 +76,6 @@ class BlogPostsController < ApplicationController |
||
| 80 | 76 |
end |
| 81 | 77 |
|
| 82 | 78 |
def authenticate_user |
| 83 |
- redirect_to new_user_session_path, alert: 'You dont have permission to access that page!' unless current_user && current_user.is_admin? |
|
| 79 |
+ redirect_to root_path, alert: 'You dont have permission to access that page!' unless current_user && current_user.admin? |
|
| 84 | 80 |
end |
| 85 | 81 |
end |
@@ -0,0 +1,2 @@ |
||
| 1 |
+module AdminPanelHelper |
|
| 2 |
+end |
@@ -14,9 +14,4 @@ class User < ActiveRecord::Base |
||
| 14 | 14 |
return name |
| 15 | 15 |
end |
| 16 | 16 |
|
| 17 |
- def is_admin? |
|
| 18 |
- #self.admin == true |
|
| 19 |
- true |
|
| 20 |
- end |
|
| 21 |
- |
|
| 22 | 17 |
end |
@@ -0,0 +1,10 @@ |
||
| 1 |
+<div class="span3" style="margin-top: 25px;"> |
|
| 2 |
+ <ul class="nav nav-pills nav-stacked"> |
|
| 3 |
+ <% if current_page?(:action => 'dashboard')%><li class="active"> <% else %><li><% end %> |
|
| 4 |
+ <%= link_to '<i class="icon-home icon-white"></i> Dashboard'.html_safe, admin_dashboard_path %></li> |
|
| 5 |
+ <% if current_page?(:action => 'posts')%><li class="active"> <% else %><li><% end %> |
|
| 6 |
+ <%= link_to '<i class="icon-file icon-white"></i> Posts'.html_safe, admin_posts_path %></li> |
|
| 7 |
+ <% if current_page?(:action => 'users')%><li class="active"> <% else %><li><% end %> |
|
| 8 |
+ <%= link_to '<i class="icon-user icon-white"></i> Users'.html_safe, admin_users_path %></li> |
|
| 9 |
+ </ul> |
|
| 10 |
+</div> |
@@ -0,0 +1,19 @@ |
||
| 1 |
+<div class="row"> |
|
| 2 |
+ <%= render 'admin_panel/sidebar_nav' %> |
|
| 3 |
+ <div class="span9"> |
|
| 4 |
+ <div class="hero-unit"> |
|
| 5 |
+ <h1>Dashboard</h1> |
|
| 6 |
+ <p>Welcome back <%= current_user.full_name%></p> |
|
| 7 |
+ </div> |
|
| 8 |
+ <div class="well summary"> |
|
| 9 |
+ <ul> |
|
| 10 |
+ <li> |
|
| 11 |
+ <a href="<%= admin_users_path %>"><span class="count"><%= @users.length %></span> Usuários</a> |
|
| 12 |
+ </li> |
|
| 13 |
+ <li class="last"> |
|
| 14 |
+ <a href="<%= admin_posts_path %>"><span class="count"><%= @posts.length %></span> Posts</a> |
|
| 15 |
+ </li> |
|
| 16 |
+ </ul> |
|
| 17 |
+ </div> |
|
| 18 |
+ </div> |
|
| 19 |
+</div> |
@@ -0,0 +1,38 @@ |
||
| 1 |
+<div class="row"> |
|
| 2 |
+ <%= render 'admin_panel/sidebar_nav' %> |
|
| 3 |
+ <div class="span9"> |
|
| 4 |
+ <div class="page-header"> |
|
| 5 |
+ <h1>Blog Posts <%= link_to 'New Blog post', new_blog_post_path, :class => 'btn btn-primary btn-mini' %></h1> |
|
| 6 |
+ </div> |
|
| 7 |
+ <table class="table table-bordered"> |
|
| 8 |
+ <thead> |
|
| 9 |
+ <tr> |
|
| 10 |
+ <th>Title</th> |
|
| 11 |
+ <th>Slug</th> |
|
| 12 |
+ <th>Content</th> |
|
| 13 |
+ <th>Published</th> |
|
| 14 |
+ <th>Author</th> |
|
| 15 |
+ <th></th> |
|
| 16 |
+ <th></th> |
|
| 17 |
+ <th></th> |
|
| 18 |
+ </tr> |
|
| 19 |
+ </thead> |
|
| 20 |
+ |
|
| 21 |
+ <tbody> |
|
| 22 |
+ <% @posts.each do |blog_post| %> |
|
| 23 |
+ <tr> |
|
| 24 |
+ <td><%= blog_post.title %></td> |
|
| 25 |
+ <td><%= blog_post.slug %></td> |
|
| 26 |
+ <td><%= blog_post.description %></td> |
|
| 27 |
+ <td><%= blog_post.published %></td> |
|
| 28 |
+ <td><%= blog_post.author.full_name %></td> |
|
| 29 |
+ <td><%= link_to 'Show', post_path(blog_post) %></td> |
|
| 30 |
+ <td><%= link_to 'Edit', edit_blog_post_path(blog_post) %></td> |
|
| 31 |
+ <td><%= link_to 'Destroy', blog_post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
|
| 32 |
+ </tr> |
|
| 33 |
+ <% end %> |
|
| 34 |
+ </tbody> |
|
| 35 |
+ </table> |
|
| 36 |
+ |
|
| 37 |
+ </div> |
|
| 38 |
+</div> |
@@ -0,0 +1,25 @@ |
||
| 1 |
+<div class="row"> |
|
| 2 |
+ <%= render 'admin_panel/sidebar_nav' %> |
|
| 3 |
+ <div class="span9"> |
|
| 4 |
+ <div class="page-header"> |
|
| 5 |
+ <h1>Users</h1> |
|
| 6 |
+ </div> |
|
| 7 |
+ <table class="table table-bordered"> |
|
| 8 |
+ <thead> |
|
| 9 |
+ <tr> |
|
| 10 |
+ <th>Name</th> |
|
| 11 |
+ <th>Email</th> |
|
| 12 |
+ </tr> |
|
| 13 |
+ </thead> |
|
| 14 |
+ |
|
| 15 |
+ <tbody> |
|
| 16 |
+ <% @users.each do |user| %> |
|
| 17 |
+ <tr> |
|
| 18 |
+ <td><%= user.full_name %></td> |
|
| 19 |
+ <td><%= user.email %></td> |
|
| 20 |
+ </tr> |
|
| 21 |
+ <% end %> |
|
| 22 |
+ </tbody> |
|
| 23 |
+ </table> |
|
| 24 |
+ </div> |
|
| 25 |
+</div> |
@@ -1,37 +0,0 @@ |
||
| 1 |
-<div class="page-header"> |
|
| 2 |
- <h1>Blog</h1> |
|
| 3 |
-</div> |
|
| 4 |
- |
|
| 5 |
-<table class="table table-bordered"> |
|
| 6 |
- <thead> |
|
| 7 |
- <tr> |
|
| 8 |
- <th>Title</th> |
|
| 9 |
- <th>Slug</th> |
|
| 10 |
- <th>Content</th> |
|
| 11 |
- <th>Published</th> |
|
| 12 |
- <th>Author</th> |
|
| 13 |
- <th></th> |
|
| 14 |
- <th></th> |
|
| 15 |
- <th></th> |
|
| 16 |
- </tr> |
|
| 17 |
- </thead> |
|
| 18 |
- |
|
| 19 |
- <tbody> |
|
| 20 |
- <% @blog_posts.each do |blog_post| %> |
|
| 21 |
- <tr> |
|
| 22 |
- <td><%= blog_post.title %></td> |
|
| 23 |
- <td><%= blog_post.slug %></td> |
|
| 24 |
- <td><%= blog_post.description %></td> |
|
| 25 |
- <td><%= blog_post.published %></td> |
|
| 26 |
- <td><%= blog_post.author.full_name %></td> |
|
| 27 |
- <td><%= link_to 'Show', post_path(blog_post) %></td> |
|
| 28 |
- <td><%= link_to 'Edit', edit_blog_post_path(blog_post) %></td> |
|
| 29 |
- <td><%= link_to 'Destroy', blog_post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
|
| 30 |
- </tr> |
|
| 31 |
- <% end %> |
|
| 32 |
- </tbody> |
|
| 33 |
-</table> |
|
| 34 |
- |
|
| 35 |
-<br> |
|
| 36 |
- |
|
| 37 |
-<%= link_to 'New Blog post', new_blog_post_path %> |
@@ -1,8 +1,6 @@ |
||
| 1 | 1 |
<div class="container nav-collapse"> |
| 2 | 2 |
<ul class="nav"> |
| 3 | 3 |
<li><%= link_to "Blog", blog_path %></li> |
| 4 |
- <li><%= link_to "Link2", "#" %></li> |
|
| 5 |
- <li><%= link_to "Link3", "#" %></li> |
|
| 6 | 4 |
</ul> |
| 7 | 5 |
|
| 8 | 6 |
<ul class="nav pull-right"> |
@@ -12,6 +10,9 @@ |
||
| 12 | 10 |
<%= current_user.full_name %> <b class="caret"></b> |
| 13 | 11 |
</a> |
| 14 | 12 |
<ul class="dropdown-menu"> |
| 13 |
+ <% if current_user.admin %> |
|
| 14 |
+ <li><%= link_to 'Admin Panel', admin_dashboard_path %></li> |
|
| 15 |
+ <% end %> |
|
| 15 | 16 |
<li><%= link_to 'Account', edit_user_registration_path %></li> |
| 16 | 17 |
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li> |
| 17 | 18 |
</ul> |
@@ -1,2 +1,9 @@ |
||
| 1 |
-<h1>Start#index</h1> |
|
| 2 |
-<p>Find me in app/views/start/index.html.erb</p> |
|
| 1 |
+<div class="hero-unit"> |
|
| 2 |
+ <h1>Website Name</h1> |
|
| 3 |
+ <p>Tagline goes here</p> |
|
| 4 |
+ <p> |
|
| 5 |
+ <a class="btn btn-primary btn-large"> |
|
| 6 |
+ Learn more |
|
| 7 |
+ </a> |
|
| 8 |
+ </p> |
|
| 9 |
+</div> |
@@ -1,8 +1,12 @@ |
||
| 1 | 1 |
RailsWebsiteTemplate::Application.routes.draw do |
| 2 | 2 |
|
| 3 |
+ get "admin/dashboard" => "admin_panel#dashboard", :as => :admin_dashboard |
|
| 4 |
+ get "admin" => "admin_panel#index" |
|
| 5 |
+ get "admin/posts" => "admin_panel#posts", :as => :admin_posts |
|
| 6 |
+ get "admin/users" => "admin_panel#users", :as => :admin_users |
|
| 7 |
+ |
|
| 3 | 8 |
get "blog" => "blog_posts#index", :as => :blog |
| 4 | 9 |
get "post/:id" => "blog_posts#show", :as => :post |
| 5 |
- get "admin/posts" => "blog_posts#list", :as => :post_list |
|
| 6 | 10 |
resources :blog_posts, path: '/admin/posts' |
| 7 | 11 |
|
| 8 | 12 |
get "start/index" |
@@ -0,0 +1,5 @@ |
||
| 1 |
+class AddAdminToUsers < ActiveRecord::Migration |
|
| 2 |
+ def change |
|
| 3 |
+ add_column :users, :admin, :boolean |
|
| 4 |
+ end |
|
| 5 |
+end |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 |
# |
| 12 | 12 |
# It's strongly recommended that you check this file into your version control system. |
| 13 | 13 |
|
| 14 |
-ActiveRecord::Schema.define(version: 20140918033424) do |
|
| 14 |
+ActiveRecord::Schema.define(version: 20140918040715) do |
|
| 15 | 15 |
|
| 16 | 16 |
# These are extensions that must be enabled in order to support this database |
| 17 | 17 |
enable_extension "plpgsql" |
@@ -58,6 +58,7 @@ ActiveRecord::Schema.define(version: 20140918033424) do |
||
| 58 | 58 |
t.string "last_name" |
| 59 | 59 |
t.datetime "created_at" |
| 60 | 60 |
t.datetime "updated_at" |
| 61 |
+ t.boolean "admin" |
|
| 61 | 62 |
end |
| 62 | 63 |
|
| 63 | 64 |
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree |
@@ -0,0 +1,19 @@ |
||
| 1 |
+require 'test_helper' |
|
| 2 |
+ |
|
| 3 |
+class AdminPanelControllerTest < ActionController::TestCase |
|
| 4 |
+ test "should get dashboard" do |
|
| 5 |
+ get :dashboard |
|
| 6 |
+ assert_response :success |
|
| 7 |
+ end |
|
| 8 |
+ |
|
| 9 |
+ test "should get posts" do |
|
| 10 |
+ get :posts |
|
| 11 |
+ assert_response :success |
|
| 12 |
+ end |
|
| 13 |
+ |
|
| 14 |
+ test "should get users" do |
|
| 15 |
+ get :users |
|
| 16 |
+ assert_response :success |
|
| 17 |
+ end |
|
| 18 |
+ |
|
| 19 |
+end |
@@ -0,0 +1,4 @@ |
||
| 1 |
+require 'test_helper' |
|
| 2 |
+ |
|
| 3 |
+class AdminPanelHelperTest < ActionView::TestCase |
|
| 4 |
+end |